package client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public abstract class AbstractTwoButtonDialogBox extends DialogBox {

	protected final Button okButton = new Button("OK");
	protected final Button cancelButton = new Button("Cancel");
	
	protected AbstractTwoButtonDialogBox() {
		setAnimationEnabled(true);
		customSetup();
		final VerticalPanel vp = new VerticalPanel();
		populateVerticalPanel(vp);
		final HorizontalPanel buttonPanel = new HorizontalPanel();
		cancelButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				handleCancel();
			}
			
		});
		
		okButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				handleOK();
			}
		});
		buttonPanel.add(cancelButton);
		buttonPanel.add(okButton);
		
		vp.add(buttonPanel);
		setWidget(vp);
		center();
	}
	
	protected void populateVerticalPanel(VerticalPanel vp) {
		//default is to do nothing
		assert true;
	}

	protected void customSetup() {
		//default is to do nothing
		assert true;
	}

	protected void handleCancel() {
		hide();
	}
	protected void handleOK() {
		//default do nothing
		assert true;
	}
	public void addOkClickHandler(ClickHandler clickHandler) {
		okButton.addClickHandler(clickHandler);
	}

}
